package com.itheima;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

public class ProxyDemo {
    public static void main(String[] args) {
        //真实对象
        QQCar car = new QQCar();
        //对真实对象的run方法增强
        Car proxy_car= (Car) Proxy.newProxyInstance(car.getClass().getClassLoader(), car.getClass().getInterfaces(), new InvocationHandler() {
            @Override
            public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
                if("run".equals(method.getName())) {
                    System.out.println("弹射起步");
                    return null;
                }else{
                    //原样调回
                    return method.invoke(car,args);
                }
            }
        });

        //代理对象方法
        proxy_car.run();
        proxy_car.stop();
    }
}
